********************************************************************************
**  TITLE:      il2015_ines_contact_networks                                  **  
**  AUTHOR:	    Philippe Mongrain                                             **
**  DATA:       2015                                                          **
**	DATE:		October 2022 					                              **	
**  VERSION:	Stata 16					                                  **	
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close       			  			              
log using "il2015_ines_contact_networks", replace

* Open the dataset

use "2015.dta", clear 


***************************
** INDEPENDENT VARIABLES **
***************************

* Time

gen surveydate=date(date, "DMY")

format %tdMon_DD,_CCYY surveydate

gen edate = 20150317

gen electiondate=date(string(edate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY electiondate

gen time = (electiondate - surveydate) + 1 // Add 1 to correct for election date

* Gender

gen male = sex

recode male (2=0)

* Age

replace age = . if age < 17

* Education

gen education = v128

recode education (9=.)

* Coalition preference

gen coalpref = .

replace coalpref = 9999 if v100 == .
replace coalpref = 9999 if v100 == 9

replace coalpref = 1 if v100 == 1 & coalpref!=9999

replace coalpref = 0 if v100!=1 & coalpref!=1 & coalpref!=9999

replace coalpref = . if coalpref == 9999

label define coalpref 0 "Losing preference" 1 "Winning preference"
label values coalpref coalpref

* News attentiveness

gen news = v85

recode v85 (9=.)

* Minimum threshold for representation in elections to the Knesset - Correct answers (3.25%; close answers also considered as correct) = 1, Incorrect answer = 0

gen threshold = v86

recode threshold (9=.)

replace threshold = 0 if threshold!=1 & threshold!=2 & threshold!=. // Incorrect answer
replace threshold = 1 if threshold == 1 // Correct answer
replace threshold = 1 if threshold == 2 // Correct answer

* Percentage of the overall government budget for security - Correct answers (between 10% and 40%) = 1, Incorrect answer = 0

gen security = v109

recode security (9=.)

replace security = 0 if security!=2 & security!=. // Incorrect answer
replace security = 1 if security == 2 // Correct answer

* Knesset Speaker - Correct answers (Yuli Edelstein) = 1, Incorrect answer = 0

gen speaker = v110

recode speaker (9=.)

replace speaker = 0 if speaker!=1 & speaker!=. // Incorrect answer
replace speaker = 1 if speaker == 1 // Correct answer

* Political knowledge index

gen knowledge = threshold + security + speaker

* Political discussion

gen discussion = 4 - v49

gen discussion_3pts = discussion
replace discussion_3pts = 0 if discussion == 1
replace discussion_3pts = 1 if discussion == 2
replace discussion_3pts = 2 if discussion == 3


*********************************
** NATIONAL-LEVEL EXPECTATIONS **
*********************************

* Forecasts (1 = a coalition led by Likud, 2 = a coalition led by Zionist Union, 3 = a national unity government)

gen forecast_whole = v99

recode forecast_whole (99=.)

* Identify correct forecasts

gen correct_whole_d = 0 if forecast_whole!=1 & forecast_whole!=.
replace correct_whole_d = 1 if forecast_whole == 1 & forecast_whole!=.


**********
** SAVE **
**********

save "il2015_ines.dta", replace


*******************
** MAIN ANALYSES **
*******************

* Regression analysis and percentage of correct and incorrect forecasts

logistic correct_whole_d discussion i.coalpref news knowledge age i.male education time
estimates table, star(.05 .01 .001)

tab correct_whole_d if e(sample) == 1


************************
** SUMMARY STATISTICS **
************************

label variable correct_whole_d "Coalition formed (DV)"
label variable discussion "Discussion"
label variable coalpref "Coalition preference"
label variable news "News attentiveness"
label variable knowledge "Political knowledge"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable time "Time of interview"

estpost tabstat correct_whole_d discussion coalpref news knowledge age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "il2015_ines_summary_national.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 2015 Israeli legislative election (INES), national level") replace

eststo clear

log close